#include <stdio.h>
#include <stdlib.h>

#define MAX 100

struct Queue
{
    int items[MAX];
    int front;
    int rear;
};

void initQueue(struct Queue *queue)
{
    queue->front = -1;
    queue->rear = -1;
}

int isFull(struct Queue *queue)
{
    return queue->rear == MAX - 1;
}

int isEmpty(struct Queue *queue)
{
    return queue->front == -1;
}

void enqueue(struct Queue *q, int item)
{
    if (isFull(q))
    {
        printf("Queue is full\n");
        return;
    }
    if (isEmpty(q))
    {
        q->front = 0;
    }
    q->items[++q->rear] = item;
}

int dequeue(struct Queue *q)
{
    if (isEmpty(q))
    {
        printf("Queue is empty\n");
        return -1;
    }
    int item = q->items[q->front];
    if (q->front >= q->rear)
    {
        q->front = -1;
        q->rear = -1;
    }
    else
    {
        q->front++;
    }
    return item;
}

int main()
{
    struct Queue q;
    initQueue(&q);
    enqueue(&q, 10);
    enqueue(&q, 20);
    enqueue(&q, 30);
    printf("Dequeued element:\n");
    while (!isEmpty(&q))
    {
        printf("%d\n", dequeue(&q));
    }
    return 0;
}